package com.juzipi.demo.mapper;

import com.juzipi.demo.pojo.Student;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface StudentMapper extends Mapper<Student> {


    //查询所有数据，简单的一个多表练习
    @Select("select t1.name,t1.age,t1.gender,t1.info,t2.d_name from student t1,stu_dept t2 where #{dept_id} = d_Id")
    List<Student> queryStudentAndDept(Integer deptId);

    // % 一直拼接不上，百度了半天还真行了，用 \ 转义符
    //模糊查询返回部分数据
    @Select("select t1.name,t1.age,t1.gender from student t1 where ( (name like \"%\" #{key} \"%\" or age like \"%\" #{key} \"%\" or gender like \"%\" #{key} \"%\") )")
    List<Student> queryStudentPart(String key);


    //查询年龄最大的,感觉意义不大，直接写死
    @Select("select * from student where age = (select MAX( age ) from student)")
    List<Student> queryStudentMaxAge(String key);

    //多表
    @Select("select * from stu_dept t1,student t2 where t1.d_id = t2.dept_id and d_name = #{key}")
    List<Student> queryStudentDept(String key);

    //需要一个student对象
    @Select("select * from student")
    Student queryStudent();


}
